#include<iostream>
#include<sys/types.h>
#include<sys/shm.h>
#include<unistd.h>
#include<sys/ipc.h>
#include<string>
#include<cstring>
using std::cout;
using std::endl;

const std::string Pathname = "/home/ddsm/_11_26_work";
const int proj_id = 0x55;

enum NUM
{
	SIZE = 4096,

};

int main()
{
	key_t key = ftok(Pathname.c_str(),proj_id);
	if(key < 0)
	{
		perror("ftok fail!");
		exit(1);
	}

	int shmid = shmget(key,SIZE,IPC_CREAT | IPC_EXCL | 0666);
	if(shmid < 0)
	{
		perror("shmget fail!");
		exit(1);
	}
	//get shm done
	char* pshm = (char*)shmat(shmid,nullptr,0);
	
	char str[] = "I am Process A";
	int n = strlen(str);
	for(int i = 0;i < n;++i)
	{
		*(pshm + i) = str[i];
	}

	sleep(10);

	shmdt(pshm);

	shmctl(shmid,IPC_RMID,nullptr);

	return 0;
}
